﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanlyDanhsachThiCapPhong
{
    public partial class frmThemHoiDongThi : Form
    {
        private string fixDir = "C:\\Database\\Data.dat";
        public frmThemHoiDongThi()
        {
            InitializeComponent();
        }

        private void btThem_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtHoiDongThi.Text.Equals("") || txtHoiDongThi.Text == null)
                    MessageBox.Show("Hãy nhập tên hội đồng thi");
                else
                {
                    HoiDongThi hdt = new HoiDongThi();
                    hdt.ThemHoiDongThi(txtHoiDongThi.Text);
                    this.dgvHoiDongThi.DataSource = hdt.ListHoiDongThi();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi dữ liệu");
            }
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            int rowIndex = this.dgvHoiDongThi.CurrentCell.RowIndex;
            DataTable dt = (DataTable)this.dgvHoiDongThi.DataSource;
            object[] fields = dt.Rows[rowIndex].ItemArray;
            string hid = fields[0].ToString();
            HoiDongThi hdt = new HoiDongThi();
            try
            {
                hdt.XoaHoiDongThi(hid);
                this.dgvHoiDongThi.DataSource = hdt.ListHoiDongThi();
            }
            catch (Exception ex) 
            {
                MessageBox.Show("Không thể xóa hội đồng thi này");
            }
        }

        private void frmThemHoiDongThi_Load(object sender, EventArgs e)
        {
            HoiDongThi hdt = new HoiDongThi();
            this.dgvHoiDongThi.DataSource = hdt.ListHoiDongThi();
        }

    }
}
